﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComUIControl
{
    public partial class SPMessageBox : Form
    {
        public SPMessageBox()
        {
            InitializeComponent();
        }

        private delegate void SetTextHandler(string text);
        public void SetName(string text)
        {
            if (this.labelTitle.InvokeRequired)
            {
                this.BeginInvoke(new SetTextHandler(SetName), text);
            }
            else
            {
                this.Text = text;
            }
        }

        public void SetTip(string text)
        {
            if (this.labelTitle.InvokeRequired)
            {
                this.BeginInvoke(new SetTextHandler(SetTip), text);
            }
            else
            {
                this.labelTitle.Text = text;
            }
        }

        public void ReLayout()
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action(ReLayout));
            }
            else
            {
                if (labelTitle.Width > 25)
                {
                    int x = (this.Width - labelTitle.Width) / 2;
                    labelTitle.Location = new Point(x,100);
                }
            }
        }

        private void SPMessageBox_Load(object sender, EventArgs e)
        {
            ReLayout();
        }

        private void buttonNo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void buttonYes_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
    }
}
